# _*_ coding：UTF-8 _*_
# @Time：2021/9/411:19
# @Author：JYZ
# @Project：oneWork


import urllib.request
import urllib.parse

# GET 请求单个参数 编码格式化

# url = "https://fanyi.baidu.com/sug"

url = "https://fanyi.baidu.com/v2transapi?from=en&to=zh"

#  注意请求头参数 【Cookie】
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36",
	"sec-ch-ua-platform": "Windows",
	"Origin": "https://fanyi.baidu.com",
	"Sec-Fetch-Site": "same-origin",
	"Sec-Fetch-Mode": "cors",
	"Sec-Fetch-Dest": "empty",
	"Referer": "https://fanyi.baidu.com/?aldtype=16047",
	# "Accept-Encoding": "gzip, deflate, br",
	"Accept-Language": "zh-CN,zh;q=0.9",
	"Cookie": "BIDUPSID=6AE8B0250987276BCD42ABDF8983EED5; PSTM=1614908299; REALTIME_TRANS_SWITCH=1; SOUND_SPD_SWITCH=1; HISTORY_SWITCH=1; FANYI_WORD_SWITCH=1; SOUND_PREFER_SWITCH=1; BDUSS=3lET0dYT0ZHeHhGZ3NhV1U4ajJ5OG1RYXE2ZUVDeWxhfm1ieHN0SmFVOUFoWmRnRVFBQUFBJCQAAAAAAAAAAAEAAACkrxGxV1dQX8X0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAED4b2BA-G9gZ; BDUSS_BFESS=3lET0dYT0ZHeHhGZ3NhV1U4ajJ5OG1RYXE2ZUVDeWxhfm1ieHN0SmFVOUFoWmRnRVFBQUFBJCQAAAAAAAAAAAEAAACkrxGxV1dQX8X0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAED4b2BA-G9gZ; __yjs_duid=1_2dfb879805221179d6402189513412441620377101148; BAIDUID=60346107B0BC082C1774C36E81B12D66:FG=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; delPer=0; BAIDUID_BFESS=73281B072E0763A71BD1FBD8CCF6909F:FG=1; ZD_ENTRY=baidu; BDRCVFR[FhauBQh29_R]=mbxnW11j9Dfmh7GuZR8mvqV; BDRCVFR[rePVrIVEn7n]=9xWipS8B-FspA7EnHc1QhPEUf; BDRCVFR[YDNdHN8k-cs]=9xWipS8B-FspA7EnHc1QhPEUf; BDRCVFR[tox4WRQ4-Km]=mk3SLVN4HKm; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; BDRCVFR[CLK3Lyfkr9D]=mk3SLVN4HKm; PSINO=1; H_PS_PSSID=31253_26350; BA_HECTOR=808k2ka0ahag00a4bv1gj634r0q; BCLID=11145813255669776526; BDSFRCVID=RrKOJexroG0YyvRH-Io0uFtwvLweG7bTDYLEOwXPsp3LGJLVJeC6EG0Pts1-dEu-EHtdogKKLmOTHpKF_2uxOjjg8UtVJeC6EG0Ptf8g0M5; H_BDCLCKID_SF=tJAqVID2tD-3fP36q6_WK-FSqxby26nj-bb9aJ5nJDonOM3lXfn1qJDn0qol-nbqte0HQ40aQpP-HJAGhl7aXfcD0R7y-JOR0C-OKl0MLnolbb0xynoDjfus5UnMBMnramOnaPJc3fAKftnOM46JehL3346-35543bRTLnLy5KJtMDF4jTKWD5OBDHRKaRJ0bIIXLb5_2Rj_JRnphCTjhPrMbtuLWMT-0bFHWxoo3xT8O5CwQ5QhQR0W5G_f5l3itan7_JjOt4oNDDKRKj-Kjn8OX-JTbMQxtNR90DnjtpvhHlrl0T5obUPUXMc9LUvjW2cdot5yBbc8eIna5hjkbfJBQttjQn3hfIkj2CKLtD0hhDLxD6D35n-Wqx7th4_XKKOLVbuX0l7keq8CD6jKMpk0jPALq4TRbmcJL-Q1Lnj6el72y5jtDUCQ-fb0hRTA5errXnAELKjpsIJMe-DWbT8U5f5wqljaaKviahREBMb1qhvDBT5h2M4qMxtOLR3pWDTm_q5TtUJMeCnTD-Dhe6oM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# 将中文转码 unicode 编码（import urllib.parse）
data = {"from": "en",
        "to": "zh",
        "query": "password",
        "transtype": "translang",
        "simple_means_flag": "3",
        "sign": "643438.864863",
        "token": "6369f83d52b58bec825e8d85fb95f541",
        "domain": "common", }

data = urllib.parse.urlencode(data).encode("utf-8")

# 请求对象的定制
request = urllib.request.Request(url=url, data=data, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode("utf-8");

# 得到的内容序列化
import json

obj = json.loads(content)
print(obj)
